package admin;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;

public class RoleMenu extends Model<RoleMenu> {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static final RoleMenu dao = new RoleMenu();
	
	/**
	 * 判断用户是否有菜单权限
	 * 
	 * @param code 图书馆编码
	 * @return
	 */
	public boolean checkRole(int adminid,String url){
		try {
			if(adminid == 1){
				return true;
			}
			String sql = "select count(1) from role_menu where roleid=" +
					"(select roleid from admin where id=?) and menuid=" +
					"(select id from menu where url = ?)";
			if(Db.queryLong(sql, adminid,url)>0)
				return true;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}
	
	/**
	 * 根据角色获取所有菜单权限
	 * @return
	 */
	public List<RoleMenu> findAllByRoleId(int roleid){
		return dao.find("select * from role_menu where roleid = ?" , roleid);
	}

	
}
